<template>
  <div>
    <div class="toolbar">
      <el-form :inline="true" :model="q" size="mini">
        <el-form-item label="申诉单号:">
          <el-input v-model="q.data_id" placeholder="申诉单号" prefix-icon="el-icon-edit"></el-input>
        </el-form-item>

        <el-form-item label="商户订单号:">
          <el-input v-model="q.pay_id" placeholder="商户订单号" prefix-icon="el-icon-edit"></el-input>
        </el-form-item>
        <el-form-item label="用户ID:">
          <el-input v-model="q.player_id" placeholder="用户ID" prefix-icon="el-icon-edit"></el-input>
        </el-form-item>
        <el-form-item label="支付类型:">
          <el-select v-model="q.pay_type" clearable placeholder="请选择">
            <el-option v-for="(name,val) in pay_type" :key="val" :label="name" :value="val">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="申诉渠道:">
          <el-select v-model="q.appeal_type" clearable placeholder="请选择">
            <el-option v-for="(val,name) in appealType" :key="val" :label="val" :value="name">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="申诉状态:">
          <el-select v-model="q.status" clearable placeholder="请选择">
            <el-option v-for="(val,name) in {0:'未处理',1:'已处理'}" :key="name" :label="val" :value="name">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="用户姓名:">
          <el-input v-model="q.pay_name" placeholder="用户姓名" prefix-icon="el-icon-edit"></el-input>
        </el-form-item>
        <el-form-item label="充值金额:">
          <el-input v-model="q.amount_start" style="width: 100px;" prefix-icon="el-icon-edit"></el-input>
          <span>至</span>
          <el-input v-model="q.amount_end" placeholder="" style="width: 100px;" prefix-icon="el-icon-edit"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="text" disabled>{{this.Timetype?'交易时间':'申诉时间'}}
          </el-button>
          (
          <el-button type="text" @click="toggleTimetype">点击切换</el-button>
          )
          <el-date-picker v-if="Timetype" v-model="q.pay_at_start" value-format="yyyy-MM-dd HH:mm:ss" type="datetime"
            placeholder="选择日期时间"></el-date-picker>
          <el-date-picker v-else v-model="q.updated_at_begin" value-format="yyyy-MM-dd HH:mm:ss" type="datetime"
            placeholder="选择日期时间"></el-date-picker>
          -
          <el-date-picker v-if="Timetype" v-model="q.pay_at_end" value-format="yyyy-MM-dd HH:mm:ss" type="datetime"
            placeholder="选择日期时间"></el-date-picker>
          <el-date-picker v-else v-model="q.created_at_end" value-format="yyyy-MM-dd HH:mm:ss" type="datetime"
            placeholder="选择日期时间"></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="query">查询</el-button>
          <el-button type="danger" @click="reload">重置</el-button>
        </el-form-item>
      </el-form>
    </div>

    <el-table class="el-calendar-table" :data="listData.items" v-loading.body="listLoading" size="mini" stripe border
      fit highlight-current-row @selection-change="handleSelectionChange">
      <el-table-column prop="id" label="申诉单号" width="80">
      </el-table-column>
      <el-table-column prop="appeal_type" label="申诉渠道" width="120">
        <template slot-scope="scope">
          {{appealType[scope.row.appeal_type]}}
        </template>
      </el-table-column>
      <el-table-column prop="pay_id" label="商户订单号" width="180">
      </el-table-column>
      <el-table-column width="120" prop="pay_type" label="支付类型">
        <template slot-scope="scope">
          {{pay_type[scope.row.pay_type]}}
        </template>
      </el-table-column>
      <el-table-column width="100" prop="player_id" label="用户ID">
      </el-table-column>
      <el-table-column width="130" prop="pay_name" label="用户姓名">
      </el-table-column>
      <el-table-column width="100" prop="amount" label="充值金额">
      </el-table-column>
      <el-table-column width="160" prop="pay_at" label="交易时间">
      </el-table-column>
      <el-table-column min-width="160" prop="created_at" label="申诉时间">
      </el-table-column>
      <el-table-column min-width="160" prop="finish_at" label="处理时间">
      </el-table-column>
      <el-table-column width="100" prop="status" label="申诉状态">
        <template slot-scope="scope">
          {{scope.row.status === 0?'未处理':'已处理'}}
        </template>
      </el-table-column>
      <el-table-column width="210" prop="handler" label="操作人">
      </el-table-column>
      <el-table-column label="操作" width="90" fixed="right">
        <template slot-scope="scope">
          <div>
            <el-button :type="scope.row.status === 0?'success':'primary'" size="mini" @click="Details(scope.row)">
              {{scope.row.status === 0?'处理':'详情'}}</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="q.page_no"
        :page-sizes="$store.state.app.pageSizeArr" :page-size="q.page_size"
        layout="total, sizes, prev, pager, next, jumper" :total="listData.total">
      </el-pagination>
    </div>
    <save-update  v-dialogDrag  v-if="showUpdate" :showUpdate.sync="showUpdate" :id="show_id"></save-update>
  </div>
</template>

<script>
import { getAppeal } from '@/api'
import { queryFilter } from '@/utils/patch'
import saveUpdate from './saveUpdate'

export default {
  name: "index",
  components: { saveUpdate },
  data () {
    return {
      show_id: null,
      listData: {},
      q: { page_size: 30, page_no: 1 },
      listLoading: false,
      showUpdate: false,
      problemsTypeList: [],
      Timetype: true,
      pay_type: this.$store.state.app.pay_type,
      appealType: this.$store.state.app.AppealType
    }
  },
  created () {
    this.getList()
  },
  methods: {
    add () {
      this.show_id = null
      this.showUpdate = true
    },
    Details (row) {
      this.show_id = row.id
      this.showUpdate = true
    },
    sendMsg (row) {
      console.log(row)
    },
    query () {
      this.q = Object.assign(this.q, { page_no: 1, page_size: 30 })
      this.getList()
    },
    reload () {
      this.q = { page_no: 1, page_size: 30 }
      this.getList()
    },
    handleSizeChange (val) {
      this.q.page_size = val
      this.getList()
    },
    handleCurrentChange (val) {
      this.q.page_no = val
      this.getList()
    },

    getList () {
      queryFilter(this.q)
      this.listLoading = true
      getAppeal(this.q).then(res => {
        if (res.status === 0) {
          this.listLoading = false
          this.listData = res.data
        }
      })
    },
    handleSelectionChange (sel) {
      console.log(sel)
    },
    toggleTimetype () {
      if (this.Timetype) {
        delete this.q.created_at_begin
        delete this.q.created_at_end
        this.Timetype = !this.Timetype
      } else {
        delete this.q.updated_at_begin
        delete this.q.updated_at_end
        this.Timetype = !this.Timetype
      }
    },
  },
  watch: {
    showUpdate () {
      if(this.showUpdate!==0&&!this.showUpdate){
        this.getList()
      }
    }
  }
}
</script>

<style scoped>
.el-form-item__label {
  width: 100px !important;
}
</style>
